/**
 * Created by kaibb on 2016/6/5.
 */

$(function () {
        var baseUrl = $("#base").attr("href");
        $.refresh = function () {
            $.ajax({
                type: "get",
                url: baseUrl + "/util/baiduTrace",
                success: function (data, textStatus) {
                    $("#progress").html(data.process + "%");
                    $("#progress").attr("aria-valuenow", data.process);
                    $("#progress").css("width", data.process + "%");
                    if (data.doing) {
                        $("#submit").attr("disabled", "disabled");
                        $("#download").toggleClass("disabled", true);
                    } else {
                        $("#submit").removeAttr("disabled");
                        $("#download").toggleClass("disabled", false);
                    }
                    $("#download").text("下载结果("+data.times+"s)");
                }
            });
        };

        $("#submit").click(function () {

            var url = $("#searchUrl").val();
            if (url.length == 0) {
                alert("查找网页不能为!");
                return;
            }
            $.ajax({
                type: "post",
                url: baseUrl + "/util/baidu",
                data: {url: url},
                success: function (data, tetStatus) {
                    $("#submit").attr("disabled", "disabled");
                    //$("#download").removeClass("disabled");
                }
            })
            ;
        });
        setInterval(function () {
            console.log("refresh.....");
            $.refresh();
        }, 500);
    }
);
